;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2021 BonfaceKilz <me@bonfacemunyoki.com>
;;; Copyright © 2021 Raghav Gururajan <rg@raghavgururajan.name>
;;; Copyright © 2022 paladhammika <paladhammika@protonmail.com>
;;; Copyright © 2021, 2022 jgart <jgart@dismail.de>
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages python)
  #:use-module (guix build-system copy)
  #:use-module (guix build-system python)
  #:use-module (guix build-system pyproject)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (gnu packages libusb)
  #:use-module (gnu packages xorg)
  #:use-module (gnu packages security-token)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages databases)
  #:use-module (gnu packages python-build)
  #:use-module (gnu packages python-check)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-build)
  #:use-module (gnu packages python-crypto)
  #:use-module (gnu packages python-science)
  #:use-module (gnu packages python-web)
  #:use-module (gnu packages sphinx)
  #:use-module (gnu packages time)
  #:use-module (gnu packages python-xyz)
  #:use-module ((guixrus licenses) #:prefix license:)
  #:use-module ((guixrus packages common python) #:prefix rus:))

;;; NOTE: This file is only for executable programs/utilities written in Python!
;;; Libraries should always go into guixrus/packages/common/python.scm.

(define-public gitauthors
  (let ((commit "e2380a35b2e9b2e0826f7527fa143b1a77848f46")
        (revision "0"))
    (package
      (name "gitauthors")
      (version "0.1.4")
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/gruns/gitauthors")
           (commit commit)))
         (file-name (git-file-name name commit))
         (sha256
          (base32 "1fh3vgj9jxpw7ddq7aaspbam7jwnrd964r10wmq7gmigdybprw99"))))
      (build-system python-build-system)
      (native-inputs
        (list python-flake8))
      (propagated-inputs
        (list python-docopt python-dulwich))
      (arguments
       '(#:phases
         (modify-phases %standard-phases
           (replace 'check
             (lambda* (#:key tests? inputs outputs #:allow-other-keys)
               (when tests?
                 (invoke "python" "tests/test_gitauthors.py")))))))
      (home-page "https://github.com/gruns/gitauthors")
      (synopsis "Get a quick summary of commit authors")
      (description
  "@code{gitauthors} is simple tool that prints a quick summary of a
  repository's authors, as collated by commits.  Summary output includes
  each author's name, email, number of commits, and date of last commit.")
      (license license:expat))))

(define-public haxor-news
  (package
    (name "haxor-news")
    (version "0.4.3")
    (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "haxor-news" version))
        (sha256
          (base32 "123z9pmxpwpklgphl70pmh9ki0jkcl8fyriv2fl9b2qgi8rzi6jv"))))
    (build-system python-build-system)
    (propagated-inputs
      (list python-click
            python-colorama
            python-prompt-toolkit
            python-pygments
            python-requests
            python-six))
    (native-inputs
      (list python-mock python-tox))
    (arguments
     '(#:tests? #f
       #:phases
       (modify-phases %standard-phases
         (delete 'sanity-check)))) ; FIXME sanity-check
     ;; ...checking requirements: ERROR: haxor-news==0.4.3
     ;; ContextualVersionConflict(prompt-toolkit 3.0.18
     ;; Requirement.parse('prompt-toolkit<1.1.0,>=1.0.0'), {'haxor-news'})
    (home-page "https://github.com/donnemartin/haxor-news")
    (synopsis "View and filter Hacker News from the command line")
    (description
"View and filter Hacker News from the command line: Posts, comments,
and linked web content.")
    (license license:asl2.0)))

(define-public python-onlykey
  (package
   (name "python-onlykey")
   (version "1.2.6")
   (source
    (origin
     (method url-fetch)
     (uri (pypi-uri "onlykey" version))
     (sha256
      (base32 "1mq02x6qncsjqadqjakywdnfclsv7jaabfk1kzwrm5x05c0hbzji"))))
   (build-system python-build-system)
   (arguments '(#:tests? #f))           ;no tests
   (native-inputs
    (list python-cython))
   (propagated-inputs
    (list python-aenum
          python-ecdsa
          python-hidapi
          python-prompt-toolkit
          python-pynacl
          python-six
          rus:python-onlykey-solo-python
          rus:onlykey-udev-rules))
   (home-page "https://github.com/trustcrypto/python-onlykey")
   (synopsis "OnlyKey client and command-line tool")
   (description "@code{OnlyKey Python Command-Line Utility} is a command line tool
targeted towards more advanced users.  This can be used for configuration and testing.")
   (license license:expat)))

(define-public roper
  (package
    (name "roper")
    (version "0.1.5")
    (source
      (origin
        (method url-fetch)
        (uri (pypi-uri "roper" version))
        (sha256
          (base32 "0p4a2h7yi4wh6gjvc5qrq6k52ly16rvm7q42pp76cnqhxpx0800s"))))
    (build-system python-build-system)
    (propagated-inputs (list python-invoke python-rope))
    (home-page "https://github.com/beat-no/roper")
    (synopsis "A CLI tool for the roper library.")
    (description "This package provides a CLI tool for the roper library.")
    (license license:gpl3+)))

(define-public python-pyment
  (package
    (name "python-pyment")
    (version "0.3.3")
    (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/dadadel/pyment")
           (commit (string-append "v" version))))
         (file-name (git-file-name name version))
         (sha256
          (base32 "0d81hk6gpll8956s10d3vm2f466s5frm7dxlk3nw0jqxgcg1va2y"))))
    (build-system python-build-system)
    (arguments
     `(#:tests? #f)) ; fixme
    (propagated-inputs (list python-pytest))
    (home-page "https://github.com/dadadel/pyment/")
    (synopsis "Format and convert Python docstrings")
    (description
"Create, update or convert docstrings in existing Python files.  Manage
several styles such as reST, javadoc, one variant of reST (re-Structured
Text, used by Sphinx), numpydoc, google docstrings, and groups.")
    (license license:gpl3+)))

(define-public python-pybase16-builder
  (package
    (name "python-pybase16-builder")
    (version "0.2.8")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "pybase16-builder" version))
              (sha256
               (base32
                "07k6ln682lzbfqw3l7qzc71r25h07i2izczdlif860qmpk7m1q8j"))))
    (build-system python-build-system)
    (propagated-inputs (list python-aiofiles python-pystache python-pyyaml))
    (home-page "https://github.com/InspectorMustache/pybase16-builder")
    (synopsis "A base16 colorscheme builder for Python")
    (description
     "This package provides a base16 colorscheme builder for Python")
    (license license:expat)))

(define-public python-interrogate
  (package
    (name "python-interrogate")
    (version "1.5.0")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "interrogate" version))
              (sha256
               (base32
                "0v3dgbzzrkyfb28ddxssdhi04q9n9lk0i1wxfz33mb44mbq2bwxn"))))
    (build-system python-build-system)
    (propagated-inputs (list python-attrs
                             python-click
                             python-colorama
                             python-py
                             python-tabulate
                             python-toml))
    (native-inputs (list python-cairosvg
                         python-pre-commit
                         python-pytest
                         python-pytest-cov
                         python-pytest-mock
                         python-sphinx
                         python-sphinx-autobuild
                         python-wheel))
    (home-page "https://interrogate.readthedocs.io")
    (synopsis "Interrogate a codebase for docstring coverage.")
    (description "Interrogate a codebase for docstring coverage.")
    (license license:none)))

(define-public python-darglint
  (package
    (name "python-darglint")
    (version "1.8.1")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "darglint" version))
              (sha256
               (base32
                "1ni0pgq48438pq8lmw9q2n4ljaq1kkmpvvp74ac1k6qlvw352388"))))
    (build-system python-build-system)
    (home-page "")
    (synopsis
     "A utility for ensuring Google-style docstrings stay up to date with the source code.")
    (description
     "This package provides a utility for ensuring Google-style docstrings stay up to
date with the source code.")
    (license license:expat)))

(define-public python-formatflowed
  (package
    (name "python-formatflowed")
    (version "2.0.0")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "formatflowed" version))
              (sha256
               (base32
                "1l642ym5phsn0y813mvdz5lba1j2dsjshvs46b9ckk29vwi27cyd"))))
    (build-system python-build-system)
    (propagated-inputs (list python-setuptools))
    (home-page "http://pypi.python.org/pypi/formatflowed")
    (synopsis "RFC 3676 format=flowed text processing")
    (description "RFC 3676 format=flowed text processing")
    (license license:psfl)))

(define-public python-nanoid
  ;; There are no tests on PyPi.
  (let ((commit "061f9a598f310b0e2e91b9ed6ce725a22770da64")
        (revision "0"))
  (package
    (name "python-nanoid")
    (version "2.0.0")
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/puyuan/py-nanoid")
           (commit commit)))
         (file-name (git-file-name name commit))
         (sha256
          (base32 "0y1bcw0h27g8rkqq7cp33ywn0i0lp0q3rjixzkh4191y1dp9yf8s"))))
    (build-system python-build-system)
    (native-inputs (list python-pytest))
    (arguments
     '(#:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda* (#:key tests? inputs outputs #:allow-other-keys)
             (when tests?
               (invoke "pytest")))))))
    (home-page "https://github.com/puyuan/py-nanoid")
    (synopsis
     "Unique string ID generator")
    (description
"This package provides a tiny, secure, URL-friendly, unique string ID
generator for Python")
    (license license:expat))))

(define-public python-bisect-demo
  (let ((commit "b750bdcf934517f39c3d0f6ff2b703eb482f0691")
        (revision "0"))
    (package
      (name "python-bisect-demo")
      (version "0.1.4")
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/takluyver/python-bisect-demo")
           (commit commit)))
         (file-name (git-file-name name commit))
         (sha256
          (base32 "1bcc33lyggahndrgwk36ziy1d2clsyn397gh2iirpvscwbdzgsq6"))))
      (build-system pyproject-build-system)
      (native-inputs
        (list python-flit
              ;; pytest is not propagated in the pyproject-build-system.
              python-pytest))
      (arguments
       '(#:phases
         (modify-phases %standard-phases
         (replace 'build
           (lambda _
             ;; A ZIP archive should be generated, but it fails with "ZIP does
             ;; not support timestamps before 1980".  Luckily,
             ;; SOURCE_DATE_EPOCH is respected, which we set to some time in
             ;; 1980.
             (setenv "SOURCE_DATE_EPOCH" "315532800")
             (invoke "flit" "build")))
           (replace 'check
             (lambda* (#:key tests? inputs outputs #:allow-other-keys)
               (when tests?
                 (invoke "pytest" "test_square.py"
                         "-vv"
                         ;; Disable the failing test.
                         "-k" "not test_square_negative")))))))
      (home-page "https://github.com/takluyver/python-bisect-demo")
      (synopsis "Demo of git bisect")
      (description
"@code{python-bisect-demo} square.py squares a number you give it.  But
it's broken with negative numbers!  I know I checked this with the first
version I wrote.  When did I break it?")
      (license license:expat))))
